#!/usr/bin/python
#-------------------------------------------------------------------------------
# Name:
# Purpose:
#
# Author:      ZWW
#
# Created:     13/05/2016
# Copyright:   (c) ZWW 2016
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import threading
import time
import ctypes
import _ctypes

class GrabThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.eventWait=threading.Event();
        self.eventWait.clear()
        self.bThreadRun = False

    def isRun(self):
        return self.bThreadRun

    def stop(self):
        if self.bThreadRun:
            self.bThreadRun = False

    def run(self):
        self.bThreadRun = True
        #self.eventWait.set()
        while self.bThreadRun:
            print "thread run\n"
            time.sleep(1)

    def getImage(self):
        if self.eventWait.wait(0.1):
            print "get\n"
        else:
            print "not get\n"

def main():
    eventObj = threading.Event()
    eventObj.clear()
    print eventObj.wait(1)
    eventObj.set()
    print eventObj.wait(1)
    print eventObj.wait(1)
    thd = GrabThread()
    thd.start()
    thd.getImage()
    time.sleep(2)
    thd.getImage()
    thd.stop()
    time.sleep(2)
    print "exit"

class keywords(ctypes.Structure):
    _fields_ = [('words', ctypes.c_char *10),]

class outStruct(ctypes.Structure):
    _fields_ = [('kws', ctypes.POINTER(keywords)),
    ('len', ctypes.c_int),]

if __name__ == '__main__':
    #main() os.path.join(_dirname , "eye4graphics"+_suffix)
    #dllObj = ctypes.CDLL("F:\\Program Files (x86)\\fMBT\\eye4graphics.dll")
    dllObj = ctypes.cdll.LoadLibrary("F:\mywork\oscQQ\OpenCVPython\stdcall\Debug\cdecl.dll")
    print dllObj.Sum(1,2)
    _ctypes.FreeLibrary(dllObj._handle)

    dllObj2 = ctypes.windll.LoadLibrary("F:\mywork\oscQQ\OpenCVPython\stdcall\Debug\stdcall.dll")
    print dllObj2.Sum(3,4)
    o = outStruct()
    dllObj2.testStruct(ctypes.byref(o))
    print o.kws[0].words;
    print o.kws[1].words;
    print o.len
    _ctypes.FreeLibrary(dllObj2._handle)
    print "exit haha"
